package xyz.quanguanjia.masterboy;

import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class MBDModifyInfoActivity extends AppCompatActivity {

    private EditText infoEditText;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_modify_info);
        infoEditText = findViewById(R.id.edit_mod_info_info);

        //导航栏
        Toolbar toolbar = findViewById(R.id.toolbar);
        Intent intent = getIntent();
        String title = "设置" + intent.getStringExtra("title");
        String hit = "输入" + intent.getStringExtra("title");
        infoEditText.setHint(hit);
        MBDToolbarUtils.setCenterTitle(toolbar, title);
        MBDToolbarUtils.backButtonClicked(toolbar, new Runnable() {
            @Override
            public void run() {
                finish();
            }
        });

        MBDToolbarUtils.toolButtonClicked(toolbar, R.id.toolbar_tv_save, new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (TextUtils.isEmpty(infoEditText.getText())) {
                    Toast.makeText(MBDModifyInfoActivity.this, "请输入群名", Toast.LENGTH_SHORT).show();
                    return;
                }

                Toast.makeText(MBDModifyInfoActivity.this, "保存成功", Toast.LENGTH_SHORT).show();

                // 在目标组件中设置回传的值
                Intent resultIntent = new Intent();

                String text = infoEditText.getText().toString();
                resultIntent.putExtra("key", text); // 设置回传的值
                setResult(RESULT_OK, resultIntent);
                finish(); // 结束目标组件，返回到源组件

            }
        });
    }
}